package com.hkts.naturalgasauthentication.base.dao;

import com.baomidou.mybatisplus.core.injector.methods.UpdateById;
import com.hkts.naturalgasauthentication.base.entity.Permission;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * 权限数据处理层
 * @author Exrick
 */
public interface PermissionDao extends ManagementBaseDao<Permission,String> {

    /**
     * 通过层级查找
     * 默认升序
     * @param level
     * @return
     */
//    @Query(value = "select Permission .id as id, Permission .createBy as createBy, Permission.createTime as create_t3_16_, Permission.del_flag as del_flag4_16_, Permission.update_by as update_b5_16_, Permission.update_time as update_t6_16_, Permission.button_type as button_t7_16_, Permission.component as componen8_16_, Permission.description as descript9_16_, Permission.icon as icon10_16_, Permission.level as level11_16_, Permission.name as name12_16_, Permission.parent_id as parent_13_16_, Permission.path as path14_16_, Permission.show_always as show_al15_16_, Permission.sort_order as sort_or16_16_, Permission.status as status17_16_, Permission.title as title18_16_, Permission.type as type19_16_, Permission.url as url20_16_ from Permission  Permission where Permission.level=:level")
    List<Permission> findByLevelOrderBySortOrder(Integer level);


    //查找第一层
    @Query("from Permission ")
    List<Permission> findFirstLevel();

    @Query("from Permission where parentId =:parentId")
    List<Permission> findByParentId(String parentId);

    /**
     * 通过parendId查找
     * @param parentId
     * @return
     */
    List<Permission> findByParentIdOrderBySortOrder(String parentId);

    /**
     * 通过类型和状态获取
     * @param type
     * @param status
     * @return
     */
    List<Permission> findByTypeAndHiddenOrderBySortOrder(Integer type, boolean status);

    /**
     * 通过名称获取
     * @param title
     * @return
     */
    List<Permission> findByTitle(String title);

    /**
     * 模糊搜索
     * @param title
     * @return
     */
    List<Permission> findByTitleLikeOrderBySortOrder(String title);

    @Override
    List<Permission> findAll();
}